Skip to content

⚡ Bolt: starter facts read two columns of the music window, not 4000 ORM rows - #376

Open
Randomname653 wants to merge 1 commit into
mainfrom
bolt/starters-facts-columns
Open

Randomname653 wants to merge 1 commit into
mainfrom
bolt/starters-facts-columns

Conversation

@Randomname653

Copy link
Copy Markdown
Owner

Problem

chat_starters.collect_facts runs on every chat open (chips) and on every starter batch. Its 14-day music window (LIMIT 4000) hydrates full WatchHistoryEntry ORM rows although only series_title and viewed_at are used; the 200-row video window uses 7 columns of ~30.

Measured on a temp DB with 384k music plays + 300 video plays (ANALYZE run), median of 9, same process, alternating order:

  • music window query: 84 ms / 44 ms (ORM) → 18 ms / 24 ms (columns); earlier run on a different seed: 78 → 16 ms.
  • whole collect_facts: ~320–360 ms → ~280–290 ms (6 statements either way; rest is unrelated).

Change

db.query(col, col) instead of db.query(WatchHistoryEntry) for the music and video windows. Same filters, same LIMIT, same dicts built from the Row. The orphan filter (with_loader_criteria) still applies to column queries — the new test seeds an orphaned play and checks it stays hidden.

Measured effect / proof

See Problem. Window query roughly 2–4x faster and no ORM instances (4200 per call before).

Tests

New tests/test_starters_facts_columns.py: counts WatchHistoryEntry load events during collect_facts and checks facts (last watched, music rotation, orphan hidden).

  • Before: 3 pass, 1 fail (ORM instances built).
  • After: 4/4.
  • Battery: 358/359; the failure is test_enrichment_status_perf.py, which also fails on untouched main in the sandbox (SQLite 3.45.1 plan) and passes in CI.

Risk & edge cases

  • Row attribute access (r.title, r.completed) is unchanged; bool(r.completed) still handles NULL.
  • No unmapped/detached-instance risk — less than before, since nothing is loaded.
  • Absolute win is tens of ms per chat open; small, but no semantic change.

Duplicate check

Searched the journal, other personas' journals, PRs for collect_facts, and the last 300 commits on main: nothing touches this.



Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants